
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml"
      xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <meta http-equiv="pragma" content="no-cache" />
    <meta http-equiv="content-type" content="no-cache, must-revalidate" />
    <meta http-equiv="expires" content="Wed, 26 Feb 1997 08:21:57 GMT"/>
    <title>课程信息</title>

    <link href="../css/bootstrap.css" rel="stylesheet"/>
    <link href="../css/font-awesome.css" rel="stylesheet"/>
    <link href="../css/custom-styles.css" rel="stylesheet"/>
    <link href="../css/element/index.css" rel="stylesheet"/>

    <style>
        [v-cloak] {
            display: none;
        }
        .table th, .table td {
            text-align: center !important;
            vertical-align: middle !important;
        }
    </style>
</head>
<body>
<div id="wrapper" v-cloak>
    <div class="row">
        <div class="col-md-12" style="height:60px;">
            <nav class="navbar navbar-default top-navbar" role="navigation">
                <div class="row">
                    <div class="col-md-2">
                        <a class="navbar-brand" style="width:100%; background-color: darkslateblue"><strong style="font-size: 20px;">学生选课管理系统</strong></a>
                    </div>
                    <div class="col-md-10">

                        <ul class="nav navbar-top-links navbar-right">
                            <li style="color: white">欢迎您，{{ user.name }}</li>
                            <li class="dropdown">
                                <a class="dropdown-toggle" data-toggle="dropdown" href="#" aria-expanded="false">
                                    <i class="fa fa-user fa-fw"></i> <i class="fa fa-caret-down"></i>
                                </a>
                                <ul class="dropdown-menu dropdown-user">
                                    <li><a href="javascript:void(0)" @click="personalPage"><i class="fa fa-user fa-fw"></i> 个人信息</a>
                                    </li>
                                    <li class="divider"></li>
                                    <li><a href="javascript:void(0)" @click="logout"><i class="fa fa-sign-out fa-fw"></i> 退出</a>
                                    </li>
                                </ul>
                            </li>
                        </ul>
                    </div>
                </div>
            </nav>
        </div>
    </div>
    <div class="row">
        <div class="col-md-2">
            <nav id="nav-id" class="navbar-default navbar-side" role="navigation">
                <div class="sidebar-collapse">
                    <ul class="nav" id="main-menu">

                        <li>
                            <a href="#"><i class="fa fa-sitemap"></i> 信息管理<span class="fa arrow"></span></a>
                            <ul class="nav nav-second-level collapse in">
								<li v-if="user.level === 1">
									<a href="adminInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">管理员信息</span></a>
								</li>
								<li v-if="user.level === 1">
									<a href="teacherInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">教师信息</span></a>
								</li>
								<li v-if="user.level === 1">
									<a href="studentInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">学生信息</span></a>
								</li>
								<li v-if="user.level === 1">
									<a href="xueyuanInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">学院信息</span></a>
								</li>
								<li v-if="user.level === 1">
									<a href="zhuanyeInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">专业信息</span></a>
								</li>
								<li>
									<a href="classInfo.html" class="active-menu"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">课程信息</span></a>
								</li>

								<li>
									<a href="xuankeInfo.html"><i class="fa fa-table sub-icon-mg" aria-hidden="true"></i><span class="mini-sub-pro">选课信息</span></a>
								</li>


                                <li>
                                    <a href="javascript:void(0)" @click="personalPage"><i class="fa fa-user"></i>个人信息</a>
                                </li>

                            </ul>
                        </li>

                        <li>
                            <a href="updatePassword.html"><i class="fa fa-unlock-alt"></i>修改密码</a>
                        </li>
                        <li>
                            <a href="javascript:void(0)" @click="logout"><i class="fa fa-power-off"></i>退出登录</a>
                        </li>
                    </ul>
                </div>
            </nav>
        </div>
        <div class="col-md-10" style="background-color: #e6e6e6">
            <div id="page-wrapper">
                <div id="page-inner">
                    <div class="row">
                        <div class="col-md-12">
                            <h1 class="page-header">
                                <small>课程信息</small>
                            </h1>
                        </div>
                    </div>

                    <div class="row">
                        <div class="panel panel-default" style="background-color: whitesmoke">
                            <div class="panel-body">
                                <div class="table-responsive">
                                    <div class="nx-table-header">
                                        <button v-if="user.level === 1" class="btn btn-sm btn-primary" @click="add()">新增</button>
                                        <input type="text" placeholder="请输入搜索内容" v-model="search" @keyup.enter="loadTable()">
                                        <i class="glyphicon glyphicon-search"></i>
                                    </div>
                                    <table class="table table-striped table-bordered table-hover">
                                        <thead>
                                        <tr>
                                            <th>课程名称</th>
                                            <th>课程介绍</th>
                                            <th>课程学分</th>
                                            <th>授课教师</th>
                                            <th>所属专业</th>
                                            <th>开班人数</th>
                                            <th>上课时段</th>
                                            <th>上课地点</th>
                                            <th>已选人数</th>
                                            <th v-if="user.level !== 2">操作</th>
                                        </tr>
                                        </thead>
                                        <tbody v-for="obj in tableData">
                                        <tr>
                                            <td>{{obj.name}}</td>
                                            <td>{{obj.description}}</td>
                                            <td>{{obj.score}}</td>
                                            <td>{{obj.teacherName}}</td>
                                            <td>{{obj.zhuanyeId}}</td>
                                            <td>{{obj.kaiban}}</td>
                                            <td>{{obj.time}}</td>
                                            <td>{{obj.location}}</td>
                                            <td>{{obj.yixuan}}</td>
                                            <td v-if="user.level !== 2">
                                                <button v-if="user.level === 3" :disabled="obj.kaiban === obj.yixuan" class="btn btn-sm btn-primary" @click="xuanke(obj)">选课</button>
                                                <button v-if="user.level === 1" class="btn btn-sm btn-primary" @click="init(obj)">编辑</button>
                                                <button v-if="user.level === 1" class="btn btn-sm btn-danger" @click="del(obj.id)">删除</button>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- 模态框（Modal） -->
    <div class="modal" tabindex="-1" role="dialog" id="mod">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <span class="modal-title">请填写信息</span>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close" @click="entity={}">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal">
                        <input type="hidden" id="id" name="id" v-model="entity.id">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">课程名称</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.name" placeholder="请输入课程名称" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">课程介绍</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.description" placeholder="请输入课程介绍" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">课程学分</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.score" placeholder="请输入课程学分" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">开班人数</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.kaiban" placeholder="请输入开班人数" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上课时段</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.time" placeholder="请输入上课时段" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上课地点</label>
                            <div class="col-sm-7 form-inline">
                                <input type="text" class="form-control" v-model="entity.location" placeholder="请输入上课地点" style="width: 100%">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">所属专业</label>
                            <div class="col-sm-7 form-inline">
                                <select class="form-control" v-model="entity.zhuanyeId" style="width: 100%">
                                    <option v-for="item in zhuanyeObjs" :value="item.id" >{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">授课教师</label>
                            <div class="col-sm-7 form-inline">
                                <select class="form-control" v-model="entity.teacherId" style="width: 100%">
                                    <option v-for="item in teachernObjs" :value="item.id" >{{item.name}}</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal" @click="entity={sex:'男'}">关闭</button>
                    <button type="button" class="btn btn-primary" v-on:click="update()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="../js/jquery-1.10.2.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/jquery.metisMenu.js"></script>
<script src="../js/custom-scripts.js"></script>
<script src="../js/my.js"></script>
<script src="../js/vue2.6.11/vue.min.js"></script>
<script src="../js/vue2.6.11/axios.js"></script>
<script src="../js/element/index.js"></script>

<script>
    function msg(type, msg) {
        Vue.prototype.$message({
            type: type, // success（成功）、warning（警告）, error(错误)
            message: msg,
            duration: 2000,
            offset: 100,
            center: true
        })
    }

    new Vue({
        el: '#wrapper',
        data: {
            entity: {},
            user: {},
            search: null,
            zhuanyeObjs: [],
            teachernObjs: [],
            tableData: []
        },
        created: function () {
            const menuHeight = document.getElementById("main-menu").getElementsByTagName('li').length * 53;
            const bodyHeight = document.getElementsByTagName("body")[0].clientHeight;
            document.getElementById("nav-id").style.height = (menuHeight > bodyHeight ? menuHeight : bodyHeight) + 'px';
            this.user = JSON.parse(localStorage.getItem('user'));

            this.loadZhuanyes();
            this.loadTeachers();
            this.loadTable();

        },
        methods: {

            loadTable() {
                let url = "/classInfo";
                if (this.search) {
                    url = url + "/" + this.search;
                }
                axios.get(url).then(res => {
                    if (res.data.code === '0') {
                        this.tableData = res.data.data;
                    } else {
                        msg("error", res.data.msg)
                    }
                })
            },

            add() {
                this.entity = {};
                $("#mod").modal("show");
            },

            init(obj) {
                this.entity = JSON.parse(JSON.stringify(obj));
                $("#mod").modal("show");
            },

            loadZhuanyes() {
                axios.get("/zhuanyeInfo").then(res => {
                    if (res.data.code === '0') {
                        this.zhuanyeObjs = res.data.data;
                    } else {
                        msg("error", res.data.msg)
                    }
                })
            },

            loadTeachers() {
                axios.get("/teacherInfo").then(res => {
                    if (res.data.code === '0') {
                        this.teachernObjs = res.data.data;
                    } else {
                        msg("error", res.data.msg)
                    }
                })
            },

            update() {
                if (this.entity.id) {
                    // 编辑
                    axios.put("/classInfo", this.entity).then(res => {
                        if (res.data.code === '0') {
                            msg("success", "编辑成功");
                            $("#mod").modal("hide");
                            this.loadTable();
                        } else {
                            msg("error", res.data.msg)
                        }
                    })
                } else {
                    // 新增
                    axios.post("/classInfo", this.entity).then(res => {
                        if (res.data.code === '0') {
                            msg("success", "新增成功");
                            $("#mod").modal("hide");
                            this.loadTable();
                        } else {
                            msg("error", res.data.msg)
                        }
                    })
                }
            },

            del(id) {
                let that = this;
                this.$confirm('确认删除？', '系统提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    cancelButtonClass: 'btn-custom-cancel',
                    type: 'warning'
                }).then(function(){
                    // 删除
                    axios.delete("/classInfo/" + id).then(res => {
                        if (res.data.code === '0') {
                            msg("success", "删除成功");
                            that.loadTable();
                        } else {
                            msg("error", res.data.msg)
                        }
                    })
                }).catch(function() {
                    console.log("取消成功！");
                });
            },

            xuanke(obj) {
                axios.post("/classInfo/xuanke", JSON.parse(JSON.stringify(obj))).then(res => {
                    if (res.data.code === '0') {
                        msg("success", "选课成功");
                        this.loadTable();
                    } else {
                        msg("error", res.data.msg)
                    }
                })
            },

            logout() {
                logout();
            }
        }
    })
</script>
</body>
</html>